package com.gxufl.console;

import java.util.List;
import java.util.Scanner;

import com.gxufl.entity.Notice;
import com.gxufl.service.NoticeService;

public class NoticeConsole {
	
	NoticeService service = new NoticeService();

	public void searchNotice() {
		NoticeService service = new NoticeService();
		List<Notice> list = service.searchNotice();
		// for打印输出
		for (int i = 0, ii = list.size(); i < ii; i++) {
			Notice notice = list.get(i);
			System.out.println(String.format("%d、%s 上映《%s》", (i+1),notice.showdate, notice.name));
		}
	}

	/**
	 * 处理保存海报逻辑
	 */
	public void saveNotice() {
		Scanner scanner = new Scanner(System.in);

		System.out.println("请输入电影名称：");
		String name = scanner.next();
		System.out.println("请输入电影介绍：");
		String content = scanner.next();
		System.out.println("请输入电影上映日期（格式为YYYY-MM-DD）：");
		String showdate = scanner.next();
		System.out.println("请输入电影优先级：");
		Integer priority = scanner.nextInt();

		Notice notice = new Notice(name, content, showdate, priority);
		service.saveNotice(notice);
	}

	/**
	 * 处理删除海报逻辑
	 */
	public void deleteNotice() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入需要删除的电影名称：");
		String name = scanner.next();

		service.deleteNotice(name);
	}
	
	
	/**
	 * 处理保存海报逻辑
	 */
	public void updateNotice() {
		// 1、要求输入需要跟新的电影名称
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入需要更新的电影名称：");
		String name = scanner.next();
		
		// 2、根据电影名称查出电影实体
		
		List<Notice> list = service.searchNotice(name, null);
		// 2-1、验证list的数量，如果不为1，那么给出错误提示
		
		
		
		// 3、 修改实体对应属性
		
		Notice notice = list.get(0);
		
		System.out.println("请输入电影《"+notice.name+"》的简介：");
		String content = scanner.next();
		
		notice.content = content;
		
		// 4、对修改后的实体进行保存
		
		service.saveNotice(notice);
	}
}
